import akshare as ak
import pandas as pd

def bond_cov_comparison():
    # 东方财富 可转债比价表
    bond_cov_comparison_df = ak.bond_cov_comparison()
    print(bond_cov_comparison_df)
    bond_cov_comparison_df.to_csv("D:\\learn_and_test_data\\akshare_bond_cov_comparison.csv", encoding="GBK", index=False)


def bond_cov_jsl():
    # 集思录 可转债转股价变动
    bond_convert_jsl_df = ak.bond_cov_jsl()
    print(bond_convert_jsl_df)
    bond_convert_jsl_df.to_csv("D:\\learn_and_test_data\\akshare_bond_convert_jsl.csv", encoding="GBK", index=False)
    premium_df = bond_convert_jsl_df[["bond_id", "premium_rt", "turnover_rt"]]
    premium_df["premium_rt"] = premium_df["premium_rt"].str.replace("%", "").astype("float")
    premium_df.rename(columns={"bond_id":"book_id", "premium_rt": "premium_rt"}, inplace=True)
    print(premium_df)


def premium_rt_test():
    convertible_ins = pd.read_csv("E:\\MarketData\\Timer_Data\\premium_rt.csv", index_col="book_id")
    for stock_id in ['113543.SH', '123046.SZ']:
        book_id, _ = stock_id.split('.')
        print(stock_id, convertible_ins.at[int(book_id), "premium_rt"])


if __name__ == '__main__':
    bond_cov_comparison()
